/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import vo.VOProblem;

/**
 *
 * @author santiagobaldrich
 */
@Entity
@Table(name = "Problem")
@NamedQueries(
{
    @NamedQuery(name = "Problem.findAll", query = "SELECT p FROM Problem p"),
    @NamedQuery(name = "Problem.findByIdProblem", query = "SELECT p FROM Problem p WHERE p.idProblem = :idProblem"),
    @NamedQuery(name = "Problem.findByName", query = "SELECT p FROM Problem p WHERE p.name = :name"),
    @NamedQuery(name = "Problem.findByDifficulty", query = "SELECT p FROM Problem p WHERE p.difficulty = :difficulty"),
    @NamedQuery(name = "Problem.findByTime", query = "SELECT p FROM Problem p WHERE p.time = :time")
})
public class Problem implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "idProblem")
    private Integer idProblem;
    @Basic(optional = false)
    @Column(name = "name")
    private String name;
    @Basic(optional = false)
    @Lob
    @Column(name = "description")
    private String description;
    @Basic(optional = false)
    @Column(name = "difficulty")
    private int difficulty;
    @Basic(optional = false)
    @Column(name = "time")
    private int time;
    @ManyToMany(mappedBy = "problemCollection")
    private Collection<Contest> contestCollection;
    @ManyToMany(mappedBy = "problemCollection")
    private Collection<KeyWord> keyWordCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "problem")
    private Collection<TestCase> testCaseCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "problem")
    private Collection<Submission> submissionCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "problem")
    private Collection<ProblemStats> problemStatsCollection;

    public Problem()
    {
    }

    public Problem(Integer idProblem)
    {
        this.idProblem = idProblem;
    }

    public Problem(Integer idProblem, String name, String description, int difficulty, int time)
    {
        this.idProblem = idProblem;
        this.name = name;
        this.description = description;
        this.difficulty = difficulty;
        this.time = time;
    }

    public Integer getIdProblem()
    {
        return idProblem;
    }

    public void setIdProblem(Integer idProblem)
    {
        this.idProblem = idProblem;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public String getDescription()
    {
        return description;
    }

    public void setDescription(String description)
    {
        this.description = description;
    }

    public int getDifficulty()
    {
        return difficulty;
    }

    public void setDifficulty(int difficulty)
    {
        this.difficulty = difficulty;
    }

    public int getTime()
    {
        return time;
    }

    public void setTime(int time)
    {
        this.time = time;
    }

    public Collection<Contest> getContestCollection()
    {
        return contestCollection;
    }

    public void setContestCollection(Collection<Contest> contestCollection)
    {
        this.contestCollection = contestCollection;
    }

    public Collection<KeyWord> getKeyWordCollection()
    {
        return keyWordCollection;
    }

    public void setKeyWordCollection(Collection<KeyWord> keyWordCollection)
    {
        this.keyWordCollection = keyWordCollection;
    }

    public Collection<TestCase> getTestCaseCollection()
    {
        return testCaseCollection;
    }

    public void setTestCaseCollection(Collection<TestCase> testCaseCollection)
    {
        this.testCaseCollection = testCaseCollection;
    }

    public Collection<Submission> getSubmissionCollection()
    {
        return submissionCollection;
    }

    public void setSubmissionCollection(Collection<Submission> submissionCollection)
    {
        this.submissionCollection = submissionCollection;
    }

    public Collection<ProblemStats> getProblemStatsCollection()
    {
        return problemStatsCollection;
    }

    public void setProblemStatsCollection(Collection<ProblemStats> problemStatsCollection)
    {
        this.problemStatsCollection = problemStatsCollection;
    }

    @Override
    public int hashCode()
    {
        int hash = 0;
        hash += (idProblem != null ? idProblem.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object)
    {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Problem))
        {
            return false;
        }
        Problem other = (Problem) object;
        if ((this.idProblem == null && other.idProblem != null) || (this.idProblem != null && !this.idProblem.equals(other.idProblem)))
        {
            return false;
        }
        return true;
    }

    @Override
    public String toString()
    {
        return "entities.Problem[idProblem=" + idProblem + "]";
    }

    public VOProblem getVO()
    {
        VOProblem vo = new VOProblem();
        vo.setDescription(description);
        vo.setDifficulty(difficulty);
        vo.setIdProblem(idProblem);
        vo.setName(name);
        vo.setTime(time);
        return vo;
    }

    public void setVOData(VOProblem vo)
    {
        setDescription(vo.getDescription());
        setDifficulty(vo.getDifficulty());
        setName(vo.getName());
        setTime(vo.getTime());
    }

}
